/*
 * Copyright (C) 2013 Andreas Stuetz <andreas.stuetz@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.easycarebn.main.fragment;

import android.app.Activity;
import android.content.ClipData.Item;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.easycarebn.main.appointment.Appointment;
import com.easycarebn.main.favorites.Drfavorites;
import com.easycarebn.main.utils.Utils;
import com.easycarebn.request.controller.SuggestNameType;
import com.timbacsi.main.R;

public class FragmentPageTab extends Fragment {

    private static final String ARG_POSITION = "position";
    private static final String MENU_ACTIVE = "menuactive";

    private int position;
    private int menuActive;
    private View mView;

    private final static int BACSI = 0;
    private final static int PHONGKHAM = 1;
    private final static int DVTAINHA = 2;

    private final static int CHOKHAM = 0;
    private final static int DAKHAM = 1;
    private final static int QUAHEN = 2;
    private final static int HUY = 3;
    
    public static FragmentPageTab f = null;

    public static FragmentPageTab newInstance(int position, int menuActive, Item item) {
        f = new FragmentPageTab();
        Bundle b = new Bundle();
        b.putInt(ARG_POSITION, position);
        b.putInt(MENU_ACTIVE, menuActive);

        f.setArguments(b);

        return f;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        position = getArguments().getInt(ARG_POSITION);
        menuActive = getArguments().getInt(MENU_ACTIVE);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        switch (menuActive) {
        case R.id.menu_yeuthich:
            switch (position) {
            case BACSI:
                mView = inflater.inflate(R.layout.fragment_like, null);
                break;
            case PHONGKHAM:
                mView = inflater.inflate(R.layout.fragment_like, null);
                break;

            case DVTAINHA:
                mView = inflater.inflate(R.layout.fragment_like, null);
                break;

            }

            break;
        case R.id.menu_qlhk:
            mView = inflater.inflate(R.layout.fragment_quanlihenkham, null);
            break;
        }
        return mView;

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    	  Utils.setOnTouchHideKeyboard( getActivity(),mView);
        super.onActivityCreated(savedInstanceState);

        switch (menuActive) {
        case R.id.menu_yeuthich:
            switch (position) {
            case BACSI:
                new Drfavorites(SuggestNameType.DOCTOR.getCode(), getActivity(), mView);

                break;

            case PHONGKHAM:
                new Drfavorites(SuggestNameType.CLINIC.getCode(), getActivity(), mView);

                break;
            case DVTAINHA:
                new Drfavorites(SuggestNameType.HOME_SERVICE.getCode(), getActivity(), mView);

                break;
            }

            break;
        case R.id.menu_qlhk:
            switch (position) {
            case CHOKHAM:
                new Appointment(getActivity(), mView, "waiting");
                break;
            case DAKHAM:
                new Appointment(getActivity(), mView, "accept");
                break;
            case QUAHEN:
                new Appointment(getActivity(), mView, "miss");
                break;
            case HUY:
                new Appointment(getActivity(), mView, "abort");
                break;
            }

            break;
        }
    }
}